# 1.7 Deployment under tomcat

# 0. Check web.xml configuration

A few students develop using jfinal-undertow and deploy with tomcat. However, jfinal-undertow doesn't require the web.xml file, leading to deployment failures in tomcat.

Therefore, when deploying under tomcat, you need to check if the web.xml exists and ensure that it is configured correctly. The configuration format is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>jfinal offical website</display-name>
  
  <filter>
    <filter-name>jfinal</filter-name>
    <filter-class>com.jfinal.core.JFinalFilter</filter-class>
    <init-param>
       <param-name>configClass</param-name>
       <param-value>demo.DemoConfig</param-value>
    </init-param>
  </filter>
  
  <filter-mapping>
    <filter-name>jfinal</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
 
</web-app>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Note: The para-value configuration depends on your project's specific XxxConfig package name and class name. Ensure to modify it accordingly. The rest of the configurations can be copied as is.

# 1. Specify the packaging type as war

Modify the pom.xml file and change the value of the packaging tag to war.

<packaging>war</packaging>
1

# 2. Remove jfinal-undertow and jetty-server dependencies

Modify the pom.xml file and delete all dependencies related to jfinal-undertow and jetty-server, otherwise, there will be conflicts when deployed in tomcat.

# 3. Add servlet API dependency

If your project code uses the servlet API, you need to add the following dependency for packaging:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
</dependency>
1
2
3
4
5
6

You can add this dependency when prompted during packaging. If packaging passes without issues, you can ignore it.

# 4. Packaging

Open the console, navigate to the project root directory, and execute the following command to create a war package:

mvn clean package
1

# 5. Deployment

Projects developed with jfinal are standard java web projects, so there's nothing special about the deployment process. Some deployment tips can be found in this blog post: https://my.oschina.net/jfinal/blog/353062

Note: This section only introduces development under jfinal-undertow or jetty-server and deployment under tomcat. Only in these two modes do you need to remove their dependencies. If you are using the traditional java web development method, you don't need to pay attention to this section. Please especially note the special statement: https://www.jfinal.com/doc/1-11

Last Updated: 9/17/2023, 5:25:03 AM